/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-01-31
 * Time: 13:54
 */
class Solution5 {
    public double myPow(double x, int n) {
        long N = n;
        if(N == 0) return 1.0;
        if(N < 0){
            x = 1/x;
            N = -N;
        }
        double tmp = myPow(x,(int)(N/2));
        return N % 2 == 0 ? Math.pow(tmp,2) : Math.pow(tmp,2)*x;
    }
}
 class Solution5_1  {
     public double myPow(double x, int n) {
         return n >= 0 ? pow(x,n) : 1/pow(x,-n);
     }

     public double pow(double x , int n) {
         if (n == 0) return 1.0;
         double tmp = pow(x, n / 2);
         return n % 2 == 0 ? Math.pow(tmp, 2) : Math.pow(tmp, 2) * x;
         // return n % 2 == 0 ? tmp * tmp : tmp * tmp * x;

     }
 }
public class Test5 {
}
